#ifndef __my_crc32_h__
#define __my_crc32_h__ 1
#include <stdint.h>
#include <stdlib.h>

extern 	const uint32_t crc_table[256];
uint32_t my_crc32_reflect(uint32_t data, size_t data_len);

static inline uint32_t my_crc32_init(void)
{
    return 0xffffffff;
}

static inline uint32_t my_crc32_update(uint32_t crc, const unsigned char *data, size_t data_len)
{

    unsigned int tbl_idx;

    while (data_len--) {
        tbl_idx = (crc ^ *data) & 0xff;
        crc = (crc_table[tbl_idx] ^ (crc >> 8)) & 0xffffffff;

        data++;
    }
    return crc & 0xffffffff;
}
static inline uint32_t my_crc32_finalize(uint32_t crc)
{
    return crc ^ 0xffffffff;
}
static inline uint32_t my_crc32 (const char *data, size_t data_len) {
	return my_crc32_finalize(my_crc32_update(my_crc32_init(),
						 (const unsigned char *)data,
						 data_len));
}
#endif